<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="选择材料" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script language="javascript">
	function selectProduct(index){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr;
		if ( ob_arr.length>=index ){
			var obj=ob_arr[index-1];
			arr=new Array(obj.value,obj.getAttribute("product_code"),obj.getAttribute("product_name"),obj.getAttribute("product_unit"),obj.getAttribute("stock"));
		}
		if (arr != null){
			parent.parent.popRetVal=arr;//上面有一个iframe,所以要用两个parent
			parent.parent.ClosePop();
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr;
		if(ob_arr.length>=it.getAttribute("index")){
			var obj=ob_arr[it.getAttribute("index")-1];
			arr=new Array(obj.value,obj.getAttribute("product_code"),obj.getAttribute("product_name"),obj.getAttribute("product_unit"),obj.getAttribute("stock"));
		}
		if(arr==null){
			return;
		}
		parent.parent.popRetVal=arr;
		parent.parent.ClosePop();
	}
	function doSearch(){
		var typeId="${typeId}";
		var searchKey=encodeURIComponent(document.getElementById("search_key").value.trim());
		var searchAll="",stocType="";
		if(document.getElementById("search_all").checked){
			searchAll="1";
		}
		if(document.getElementById("stoc_type")){
			if(document.getElementById("stoc_type").checked){
				stocType="UPPER_ZERO";
			}
		}
		window.location="/base/ProductListForSelect.ihtm?stock=${stock}&sto_id=${stoId}&type_id="+typeId+"&search_key="+searchKey+"&search_all="+searchAll+"&stoc_type="+stocType;
	}
	function doInit(){
		Window_Onload();
		document.getElementById("search_key").focus();
	}
	function checkSearchKey(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doNew(){
		var url="/base/ProductNew.ihtm?type_id=${typeId}";
		parent.ShowIframe("材料",url,900,420,"doProNewCallBack()");//doProNewCallBack是父窗口的
	}
	function doNewCallBack(id){//父窗口的doProNewCallBack调用
		window.location="/base/ProductListForSelect.ihtm?stock=${stock}&stoc_type=${stocType}&sto_id=${stoId}&type=${type}&id="+id;
	}
</script>
</head>
<body oncontextmenu="return false" onload="doInit();" scroll="no" style="background: #EAFAFF;">
		<div id="scrollDiv" style="OVERFLOW-Y:auto;height:348px">
		  <div class="main search-business">
			   <div class="cue-info">
					<h4>
						<c:if test="${searchAll=='1'}">所有类别 - 材料</c:if>
						<c:if test="${searchAll!='1'}">${productType.typeName} - 材料</c:if>
					</h4>				   	
			  </div>
			  <div class="content">		
			  		<table border="0" width="100%">
				  		<tr>
				  			<td width="200px">
				  				<input type="text" class="TextBox" id="search_key" name="search_key" onKeyUp="checkSearchKey();"  value="${searchKey}" title="以产品名称、产品名称拼音字头进行模糊查询">
				  			</td>
				  			<td align="right">
				  				<input type="button" class="buttom search-but" value=" 查 询" onClick="doSearch();" title="以产品名称、产品名称拼音字头进行模糊查询">
								<input type="button" class="buttom search-add" value=" 新 增" onClick="doNew();" <c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';BASE_PROD;')==-1}">disabled="true"</c:if>>
				  			</td>
				  		</tr>
				  		<tr>
				  			<td colspan="2">
				  				<input type="checkbox" id="search_all" name="search_all" <c:if test="${searchAll=='1'}">checked</c:if>>在所有类别中查找材料
				  				<c:if test="${stock=='Y'}">
				  					<br><input type="checkbox" id="stoc_type" name="stoc_type" <c:if test="${stocType=='UPPER_ZERO'}">checked</c:if>>只显示有库存的材料
				  				</c:if>
				  			</td>
				  		</tr>
				  	</table>
			  </div>			  
			  <%@include file="../inc/AlertMsg.jsp"%>
			  <div class="table-list" style="width:97%; padding:15px 0 15px 10px; float:left;">
						<table width="100%">
						<tr>
							<th width="14"></th>
							<th width="17%">类别</th>
							<th width="13%">材料编号</th>
							<c:if test="${stock=='Y'}">
								<th width="17%">品名规格</th>
								<th width="8%">单位</th>
								<th width="20%" >备注</th>
								<th width="10%" >库存</th>
							</c:if>
							<c:if test="${stock!='Y'}">
								<th width="21%">品名规格</th>
								<th width="10%">单位</th>
								<th width="24%" >备注</th>
							</c:if>
							<th width="15%">操作</th>
						</tr>
						<c:forEach var="item" items="${productList}" varStatus="i">
						<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
						<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
						<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' onmouseout='javascript:mouseout(this)' ondblclick='javascript:DoubleClick(this)' onmouseover='javascript:mouseover(this)' onClick='javascript:ClickCheck(this)'>
							<td><input type="radio" name='query_checkbox' value="${item[0]}" product_code="${item[1]}" product_name="<c:out value="${item[2]}" />" product_unit="${item[3]}" stock='${item[8]}'></td>
							<td>${item[7]}</td>
							<td>${item[1]}</td>
							<td>${item[2]}</td>
							<td>${item[3]}</td>
							<td>${item[6]}</td>
							<c:if test="${stock=='Y'}">
								<td>${item[8]}</td>
							</c:if>
							<td class="ListTd">
								<a href="javascript:selectProduct('${i.index+1}');">选择</a>
								<c:if test="${item[4]!=null && item[4]!=''}"><a href="${item[4]}" target="_blank">图片</a></c:if>
							</td>
						</tr>
						</c:forEach>
						</table> 
			  </div>
			</div>
		</div>
</body>
</html>